//
//    Copyright (C) 2012  OinkStudio
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

package oldClasses;

import java.awt.GridLayout;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import database.DataBaseAdapter;


public class TabbedPane extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private DataBaseAdapter dataBaseAdapter;

	public TabbedPane(DadesTotal totalDades) {
		super(new GridLayout(1, 1));

		JTabbedPane tabbedPane = new JTabbedPane();
		dataBaseAdapter = DataBaseAdapter.getSingleton();
		dataBaseAdapter.openBBDD();
		LinkedList<String> tables = dataBaseAdapter.getTablesFromDataBase();
		ArrayList<String> camps;
		ArrayList<Vector<Object>> totalDadesDDBB;
		Iterator<String> iteratorTables = tables.iterator();

		while (iteratorTables.hasNext()) {
			String tableName = iteratorTables.next();
			Taula auxTaula = new Taula(tableName);
			ArrayList<Object> row = new ArrayList<Object>();
			
			// Recuperamos el nombre de los campos de cada tabla
			camps = dataBaseAdapter.getColumnsFromTable(tableName);
			
			MyInteractiveForm table = new MyInteractiveForm(camps);
			
			//InteractiveForm table = new InteractiveForm(camps);
//			try {
//				totalDadesDDBB = dataBaseAdapter.fillData("select * from "
//						+ tableName, camps);
//
//				if (totalDadesDDBB != null) {
//					row = new ArrayList<Object>();
//					for (int j = 0; j < totalDadesDDBB.size(); j++) {
//
//						for (int k = 0; k < totalDadesDDBB.get(j).size(); k++) {
//							row.add(totalDadesDDBB.get(j).get(k));
//							table.getTableModel().setValueAt(
//									totalDadesDDBB.get(j).get(k), j, k);
//						}
//						auxTaula.getDadesTaula().addRow(row);
//						table.getTableModel().addEmptyRow();
//					}
//				}
//				tabbedPane.addTab(tableName, table);
//				totalDades.addTaula(auxTaula);
//				dataBaseAdapter.close();
//				// Add the tabbed pane to this panel.
//				add(tabbedPane);
//
//				// The following line enables to use scrolling tabs.
//				tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
//
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
		}
	}

	
	/*
	 * protected JComponent makeTextPanel(String text) { JPanel panel = new
	 * JPanel(false); JLabel filler = new JLabel(text);
	 * filler.setHorizontalAlignment(JLabel.CENTER); panel.setLayout(new
	 * GridLayout(1, 1)); panel.add(filler); return panel; }
	 */

	/** Returns an ImageIcon, or null if the path was invalid. */
	/*
	 * protected static ImageIcon createImageIcon(String path) { java.net.URL
	 * imgURL = TabbedPaneDemo.class.getResource(path); if (imgURL != null) {
	 * return new ImageIcon(imgURL); } else {
	 * System.err.println("Couldn't find file: " + path); return null; } }
	 */

	/**
	 * Create the GUI and show it. For thread safety, this method should be
	 * invoked from the event dispatch thread.
	 */
	/*
	 * private static void createAndShowGUI() { //Create and set up the window.
	 * JFrame frame = new JFrame("TabbedPaneDemo");
	 * frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	 * 
	 * //Add content to the window. frame.add(new TabbedPaneDemo(),
	 * BorderLayout.CENTER);
	 * 
	 * //Display the window. frame.pack(); frame.setVisible(true); }
	 */

}
